﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;


namespace CMS.BLL
{
    public class ArrivedDestination
    {
        public eArrivedDestination   Data;

        public ArrivedDestination()
        {
            Data = new eArrivedDestination();
		}

        ~ArrivedDestination()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
           cArrivedDestination objDAL = new cArrivedDestination();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cArrivedDestination objDAL = new cArrivedDestination();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cArrivedDestination objInfor = new cArrivedDestination(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.ArrivedDestinationID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
           cArrivedDestination objInfor = new cArrivedDestination();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cArrivedDestination objInfor)
        {
            objInfor.TourID = Data.TourID;
            objInfor.TourDestinationID = Data.TourDestinationID;
        }

        private void ConvertData(cArrivedDestination objInfor)
        {
            Data.TourID = objInfor.TourID;
            Data.TourDestinationID = objInfor.TourDestinationID;
        }
        public int DeleteByTourID(int TourID)
        {
            int nResult = 0;
            cArrivedDestination objInfor = new cArrivedDestination();
            try
            {
                nResult = objInfor.DeleteByTourID(TourID);
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public DataTable Search(int TourID)
        {
            DataTable tbResult = new DataTable();
            cArrivedDestination objDAL = new cArrivedDestination();
            tbResult = objDAL.Search(TourID);
            return tbResult;
        }
    }
}
